package com.netease.pluginproject;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    //加载插件
    public void loadPlugin(View view) {
        PluginManager.getInstance(this).loadPlugin();
    }
    //启动插件里面的Activity
    public void startPluginActivity(View view) {
        //占位   代理Activity

        //获取apk的绝对路径 //  sdcard/p.apk
        File file = new File(Environment.getExternalStorageDirectory(), "p.apk");
        String path = file.getAbsolutePath();

        //获取插件包 里面的Activity
        PackageManager packageManager = getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
        ActivityInfo activityInfo = packageInfo.activities[0];//插件里的第一个启动的Activity
        Log.d(TAG, "startPluginActivity: "+activityInfo.name);
        //跳转到宿主的代理activity，并且传入要跳转到的插件名
        Intent intent = new Intent(this, ProxyActivity.class);
        intent.putExtra("className",activityInfo.name);
        startActivity(intent);
    }

    private static final String TAG = "MainActivity";
}